import $service from '../../../../../service.js';
var hospital_id = "1";
var that;
var this_;
var doctor_id;
const app = getApp();
let page = 1;
Page({
    data:{
       "active" : true,
       commentlist:[],
       onMore: false
    },
    onLoad(e){
      doctor_id = e.doctor_id; 
       wx.setNavigationBarTitle({
           title: '对' + e.doctor_name + '医生的评价'
       })
    },
    onShow(){
        that = this.data;
        this_ = this;
        this.getDoctorEvaluateList();
    },
    onPullDownRefresh() {
        page = 1;
        this.getDoctorEvaluateList();
    },
    onReachBottom() {
        if (!this.data.onMore) {
            page ++
            this.getDoctorEvaluateList();
        }
    },
    getDoctorEvaluateList() {
        let params = {
            "current": page,
            "doctorId": doctor_id,
            "size": 10
          }
        app.http.getDoctorEvaluateList(params).then(res => {
            let list = res.data.list;
            if (this.data.noMore) return
            if (list.length < 10) {
                this.setData({
                    noMore: true
                })
            }
            list = that.commentlist.concat(list)
            this.setData({
                commentlist: list
            })
        }).catch(err => {
            $service.showToast(err.msg)
        }).finally(() => {
            wx.stopPullDownRefresh()
        })
    },
    previewImage: function(e) { //图片放大
        var index = e.currentTarget.dataset.index;
        var all = [];
        var projectV = this.data.commentlist[index].comment_img;
        for (var i = 0; i < projectV.length; i++) {
            all.push(projectV[i].img);
        }
        all.forEach(item => {
            item = item.replace(/https/, 'http')
        })
        wx.previewImage({
            urls: all
        })
    }
})